#include<iostream>
using namespace std;
const int N = 1e6 + 10;
int v[N], w[N];
int f[N];
int n, m;
int main()
{
	scanf("%d%d", &n, &m);
	int cnt = 1;
	for (int i = 1; i <= n; i++) {
		int v1, w1, s;
		cin >> v1 >> w1 >> s;
		for (int j = 1; j <= s; j <<= 1) {
			v[cnt] = j * v1;
			w[cnt++] = j * w1;
			s -= j;
		}
		if (s) {
			v[cnt] = s * v1;
			w[cnt++] = s * w1;
		}
	}
	for (int i = 1; i < cnt; i++) {
		for (int j = m; j >= v[i]; j--) {
			f[j] = max(f[j], f[j - v[i]] + w[i]);
		}
	}
	cout << f[m] << endl;
	return 0;
}